using System;

namespace Catastrophe.Common.Tools.Cals
{
	public class OeeCal
	{
		private const float Tolerance = 1E-07f;

		public static double Utilization(double proTime, double planTime, int decimals = 2)
		{
			if (Math.Abs(planTime) < 1.0000000116860974E-07)
			{
				return 0.0;
			}
			return Math.Round(proTime / planTime, decimals);
		}

		public static double Availability(double stopTime, double planTime, int decimals = 2)
		{
			if (Math.Abs(planTime) < 1.0000000116860974E-07)
			{
				return 0.0;
			}
			return Math.Round((planTime - stopTime) / planTime, decimals);
		}

		public static double Availability2(double proTime, double planTime, int decimals = 2)
		{
			if (Math.Abs(planTime) < 1.0000000116860974E-07)
			{
				return 0.0;
			}
			return Math.Round(proTime / planTime, decimals);
		}

		public static double Performance(int totalCount, double proTime, double planTact, int decimals = 2)
		{
			if (Math.Abs(planTact) < 1.0000000116860974E-07)
			{
				return 0.0;
			}
			return Math.Round((double)totalCount / (proTime / planTact), decimals);
		}

		public static double Qualify(int totalCount, int qualifiedProducts, int decimals = 2)
		{
			if (totalCount == 0)
			{
				return 0.0;
			}
			return Math.Round((double)qualifiedProducts / (double)totalCount, decimals);
		}

		public static double Oee(double availability, double performance, double quality, int decimals = 2)
		{
			return Math.Round(availability * performance * quality, decimals);
		}
	}
}
